

class UrlManager():
    '''
    url管理器
    '''

    def __init__(self):
        self.new_urls = set()
        self.old_urls = set()

    def add_new_url(self,url):

        #如果要添加的url为空则直接返回
        if url is None or len(url) == 0:
            return

        #判断新增的url是否在集合里
        if url in self.new_urls or url in self.old_urls:
            return

        self.new_urls.add(url)

    def add_new_urls(self, urls):
        # 如果要添加的url为空则直接返回
        if url is None or len(url) == 0:
            return
        for url in urls:
            self.add_new_url(url)

    def get_url(self):
        if self.has_new_url():
            url = self.new_urls.pop()
            self.old_urls.add(url)
            return url
        else:
            return None

    def has_new_url(self):
        return len(self.new_urls) > 0



url_manager = UrlManager()
url_manager.add_new_url("url1")
url_manager.add_new_url(["url1","url2"])

print(url_manager.new_urls, url_manager.old_urls)